package hanjia;

import java.util.HashSet;
import java.util.Stack;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/6-下午5:35
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode150 {

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();


        for (String s : tokens) {
            if ("+".equals(s)) {
                stack.push(stack.pop() + stack.pop());
            } else if ("-".equals(s)) {
                int a = stack.pop();
                int b = stack.pop();
                stack.push(b - a);
            } else if ("/".equals(s)) {
                int a = stack.pop();
                int b = stack.pop();
                stack.push(b / a);
            } else if ("*".equals(s)) {
                stack.push(stack.pop() * stack.pop());
            } else {
                stack.push(Integer.valueOf(s));
            }


        }
        return stack.pop();


    }

    public String infixToSuffix(String exp) {
        Stack<Character> stack = new Stack<>();
        StringBuilder results = new StringBuilder();
        for (char c : exp.toCharArray()) {

            int enter = getPriority(c);
            if (enter < 0) {
                results.append(c);
                continue;
            }
            if (enter > 0) {
                int high=-1;
                if (!stack.isEmpty()){
                    Character peek = stack.peek();
                     high = getPriority(peek);
                }

                if (enter>high){
                    stack.push(c);
                }else {
                    while (high>=enter){
                        Character pop = stack.pop();

                    }
                }




                }


            }



        return results.toString();


    }

    public int getPriority(char c) {
        switch (c) {
            case '*':
            case '/':
                return 2;
            case '+':
            case '-':
                return 1;
            case '(':
            case ')':
                return 0;

        }
        return -1;
    }

}
